package com.lzwork.gpt.utility.thread;

import com.lzwork.gpt.utility.caller.GptCaller;
import com.lzwork.gpt.utility.thread.MultiCaller.RunState;
import com.lzwork.utility.logger.LOGGER;

/**
 * @author LiZheng
 * @date 2024年3月14日 16:38:17
 */

public class CallerThread extends Thread
{
	public CallerThread(GptCaller caller, MultiCaller owner)
	{
		this.caller = caller;
		this.owner = owner;
	}

	protected GptCaller caller;
	protected MultiCaller owner;

	public GptCaller getCaller()
	{
		return caller;
	}

	@Override
	public void run()
	{
		while (owner.localState != RunState.Stop)
		{
			try
			{
				sleep(200);
			} catch (InterruptedException e)
			{
				e.printStackTrace();
				owner.onCallerInterupt(this);
			}

			if (owner.localState == RunState.Idle)
				continue;

			owner.doJob(this);
		}

		LOGGER.log(LOGGER.SYS, "Thread [" + caller.url() + "] exit by owner job stop.");
	}
}
